#include "multithread.h"
#include <QDebug>

uint8_t MultiThread::_stop;

MultiThread::MultiThread(QObject *parent) : QObject(parent)
{

}

//void MultiThread::doWork(const QString parameter)
//{
//    qDebug() << "MultiThread doWork--"+parameter;
//}

//MultiThread_Test1::MultiThread_Test1(QObject *parent) : MultiThread(parent)
//{
//    ;
//}

void MultiThread_Test1::doWork(const QString parameter)
{
    uint32_t count=0;
    qDebug() << "Test1 doWork--"+parameter;
    while(is_run())
    {
        qDebug() << parameter + " Test1 run--"+QString::number(count);
        emit resultReady(parameter + " Test1 run--"+QString::number(count), NULL);
        count++;
        QThread::msleep(100);
    }
}

//MultiThread_Test2::MultiThread_Test2(QObject *parent) : MultiThread(parent)
//{
//    ;
//}

void MultiThread_Test2::doWork(const QString parameter)
{
    uint32_t count=0;
    qDebug() << "Test2 doWork--"+parameter;
    while(is_run())
    {
        qDebug() << parameter + " Test2 run--"+QString::number(count);
        emit resultReady(parameter + " Test2 run--"+QString::number(count), NULL);
        count++;
        QThread::msleep(100);
    }
}


static MultiThread* _multiThread[10];
static ControllerMultiThread* _cMultiThread[10];

void MultiThreadTest_Start(void)
{
    int index=0;
    for(index=0; index<5; index++)
    {
        _multiThread[index] = new MultiThread_Test1();
    }
    for(index=5; index<10; index++)
    {
        _multiThread[index] = new MultiThread_Test2();
    }

    for(index=0; index<10; index++)
    {
        _cMultiThread[index] = new ControllerMultiThread(_multiThread[index]);
        _cMultiThread[index]->start("Thread_"+QString::number(index+1));
    }
}
void MultiThreadTest_Stop(void)
{
    MultiThread::stop();
    QThread::msleep(500);
}

